<template>
	<view class="beijingse mainpadding" v-if="pageShow">
		<view class="" style="padding-bottom: 120rpx;">
			<!-- state 1=待支付,2=待发货,3=待收货,4=待评论,5=售后订单(已弃用),6=已完成,7=已取消,8=取消审核中 -->
			<!-- buy_type 1=实物商品,2=虚拟商品 -->
			<!-- order_type 1到店自提，2物流配送 -->
			<view class="bigtext fonweight" v-if="dataAll.state==1">等待买家付款</view>
			<view class="bigtext fonweight" v-if="dataAll.state==3 && dataAll.order_type==1">待核销</view>
			<view class="bigtext fonweight" v-if="dataAll.state==2 && dataAll.order_type==2">等待商家发货</view>
			<view class="bigtext fonweight" v-if="dataAll.state==2 && dataAll.order_type==1">备货中</view>
			<view class="bigtext fonweight" v-if="dataAll.state==3 && dataAll.order_type==2">等待买家收货</view>
			<view class="bigtext fonweight" v-if="dataAll.state==4">待评价</view>
			<view class="bigtext fonweight" v-if="dataAll.state==6">已完成</view>
			<view class="bigtext fonweight" v-if="dataAll.state==7">已取消</view>
			
			<view class="strongtext nofonweight margin_top1" v-if="dataAll.state==1">请您及时付款~</view>
			<view class="strongtext nofonweight margin_top1" v-if="dataAll.state==2 && dataAll.order_type==2">请您耐心等待商家发货~</view>
			<view class="strongtext nofonweight margin_top1" v-if="dataAll.state==2 && dataAll.order_type==1">商家备货中，请耐心等待~</view>
			<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==3 && dataAll.order_type==1">请您到门店消费核销</view>
			<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==3 && dataAll.order_type==2">收到货确认无误后请点击确认收货</view>
			<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==6">订单已完成！</view>
			<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==7">订单已取消，期待下次和您的亲密接触</view>
			<!-- 地址 -->
			<view class="radius mainpadding ffffff margin_top" v-if="dataAll.order_type==2">
				<view class="flexleft">
					<view class="titletext fonweight margin_right3 zhonghei">{{dataAll.address.name}}</view>
					<view class="titletext fonweight zhonghei">{{dataAll.address.mobile}}</view>
				</view>
				<view class="titletext xiaohui margin_top2">{{dataAll.address.address}}</view>
			</view>
			<view class="radius mainpadding ffffff margin_top " v-if="dataAll.state==3 && dataAll.order_type==2">
				<view class="flexbetween">
					<view class="ershiba fonweight zhonghei">快递公司</view>
					<view class="ershiba  zhonghei">{{dataAll.express_name}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershiba fonweight zhonghei">快递单号</view>
					<view class="ershiba  zhonghei">{{dataAll.express_no}}</view>
				</view>
			</view>
			<view class="radius mainpadding ffffff margin_top " v-if="dataAll.order_type==1">
				<view class="ershiba zhonghei fonweight">核销门店</view>
				<view class="flexleft margin_top">
					<view class="ershiba zhonghei">{{dataAll.shopconfig.get_name}}</view>
					<view class="ershiba  zhonghei">{{dataAll.shopconfig.get_tel}}</view>
				</view>
				<view class="ershiba  zhonghei margin_top">{{dataAll.shopconfig.get_address}}</view>
			</view>
			<!--订单商品  -->
			<view class="ffffff radius margin_top mainpadding">
				<view class="ershiba zhonghei fonweight">订单商品</view>
				<view class="" v-for="item in dataAll.goods" :key="item.id">
					<view class="flexbetween margin_top">
						<image class="sptp" :src="item.image_text" mode=""></image>
						<view class="" style="width: 77%;">
							<view class="ershiba xiaohei yhxk">{{item.title}}</view>
							<view class="flexbetween margin_top4">
								<view class="titletext xiaocheng">¥{{item.price}}</view>
								<view class="ershil xiaohui">x{{item.number}}</view>
							</view>
						</view>
					</view>
					<!-- 退款状态:0=未退款,1=退款中,2=待退货,3=退款完成,4=退款关闭,5=退款被拒 -->
					<view class="flexright" v-if="dataAll.state==3 && dataAll.buy_type==1">
						<view class="xhbtn flexcenter margin_top" v-if="item.refund_status==0||item.refund_status==4||item.refund_status==5" @click="tzsqtk(listid,item.id)">退款/售后</view>
						<view class="xhbtn flexcenter margin_top" v-if="item.refund_status==1" @click="tuikuanxq(item.refund_id)">退款中</view>
						<view class="xhbtn flexcenter margin_top" v-if="item.refund_status==2" @click="tuikuanxq(item.refund_id)">待退货</view>
						<view class="xhbtn flexcenter margin_top" v-if="item.refund_status==3" @click="tuikuanxq(item.refund_id)">退款完成</view>
					</view>
				</view>
			</view>
			<!-- 核销码 -->
			<view class="ffffff radius margin_top mainpadding flexcenter" v-if="dataAll.state==3 && dataAll.order_type==1">
				<view class="">
					<view class="textcenter ershiba zhonghei" @click="copy(dataAll.hx_code)">{{dataAll.hx_code}}</view>
					<view class="flexcenter margin_top1">
						<uqrcode ref="uqrcode" canvas-id="qrcode" @click="ewmfn" v-bind:value="order_hxurl"
							:options="{ margin: 10}" size="120">
						</uqrcode>
					</view>
					<view class="ershiba zhonghei textcenter margin_top1">核销码</view>
				</view>
			</view>
			<view class="ffffff radius mainpadding margin_top">
				<view class="flexbetween">
					<view class="ershil zhonghei">合计</view>
					<view class="ershil xiaocheng">¥{{dataAll.total_price}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil zhonghei">首单减</view>
					<view class="ershil xiaocheng">¥{{dataAll.sdyh_price}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil zhonghei">优惠券抵扣</view>
					<view class="ershil xiaocheng">¥{{dataAll.coupon_price}}</view>
				</view>
				<!-- <view class="flexbetween margin_top">
					<view class="ershil zhonghei">消费券抵扣</view>
					<view class="ershil xiaocheng">¥{{dataAll.sdyh_price}}</view>
				</view> -->
				<view class="flexbetween margin_top">
					<view class="ershil zhonghei">联盟积分抵扣</view>
					<view class="ershil xiaocheng">¥{{dataAll.score_price}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="dataAll.state!=1&& dataAll.state!=7">
					<view class="ershil zhonghei">实际支付</view>
					<view class="ershil xiaohong">¥{{dataAll.pay_price}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil zhonghei">订单编号</view>
					<view class="ershil xiaohui">{{dataAll.order_no}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil zhonghei">下单时间</view>
					<view class="ershil xiaohui">{{dataAll.createtime_text}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="ershil zhonghei">支付方式</view>
					<view class="ershil xiaohui">{{dataAll.pay_type==10?"微信支付":"余额支付"}}</view>
				</view>
				<view class="margin_top" v-if="dataAll.remarks">
					<text class="ershil zhonghei">备注：</text>
					<text class="ershil xiaohui">{{dataAll.remarks}}</text>
				</view>
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding flexright">
			<view class="qxbtn flexcenter margin_left" v-if="dataAll.state==1 || dataAll.state==2"  @click.stop="cancelorder(dataAll.id)">取消订单</view>
			<view class="xhbtn flexcenter margin_left" v-if="dataAll.state==1"  @click.stop="payment(dataAll)">立即支付</view>
			<view class="qxbtn flexcenter margin_left" v-if="dataAll.state==6 || dataAll.state==7" @click.stop="deleteorder(dataAll.id)">删除订单</view>
			<view class="xhbtn flexcenter margin_left" v-if="dataAll.state==3 && dataAll.order_type==2" @click.stop="shouhuo(dataAll.id)">确认收货</view>
			<view class="xhbtn flexcenter margin_left" @click.stop="tzljpj(dataAll.id)" v-if="dataAll.state==4">立即评价</view>
			<view class="qxbtn flexcenter margin_left" @click.stop="cancelorder(dataAll.id)" v-if="dataAll.state==3 && dataAll.buy_type==2">取消订单</view>
			<view class=""v-if="(dataAll.state==4 || dataAll.state==6) && dataAll.is_openfp==1">
				<view class="xhbtn flexcenter margin_left" v-if="dataAll.openfg_status==1" @click.stop="kaijufp(dataAll.id)">开具发票</view>
				<view class="qxbtn flexcenter margin_left" v-if="dataAll.openfg_status==2">发票开具中</view>
				<view class="xhbtn flexcenter margin_left" v-if="dataAll.openfg_status==3" @click.stop="tzxq(dataAll.user_fp_id,dataAll.id)">查看发票</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				order_hxurl:"",
				listid:"",
				dataAll: {},
				pageShow: false
			}
		},
		onLoad(options) {
			this.listid = options.id
			
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			tzxq(id,pid) {
				uni.navigateTo({
					url: '/pages_wode/fapiaoxq?data_type=2&id='+id+"&pid="+pid
				})
			},
			kaijufp(id){
				uni.navigateTo({
					url:"/pages_wode/kaijufp?data_type=2&id="+id
				})
			},
			getsyetem(){
				httpRequest.request('/api/index/getConfigInfo', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					this.order_hxurl = res.data.order_hxurl+"?hx_code="+this.dataAll.hx_code
				})
			},
			ewmfn() {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {
						console.log(res);
						var i = [res.tempFilePath]; //获取当前页面的轮播图数据
						//uniapp预览轮播图
						uni.previewImage({
							current: 0, //预览图片的下标
							urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
						})
					}
				});
			},
			getDetail() {
				httpRequest.request('/api/order/getOrderInfo', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
					if(this.pageShow==false){
						this.getsyetem()
					}
					this.pageShow = true
				})
			},
			payment(item) {
				let data = {
					id: item.id,
					pay_price: item.pay_price,
					type: 4,
				}
				uni.navigateTo({
					url: '/pages_shouye/dingdanzf?msg=' + encodeURIComponent(JSON.stringify(data))
				})
			},
			cancelorder(id) {
				httpRequest.modal('提示', '是否确认取消当前订单', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/order/cancelOrder', 'POST', {
							order_id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.getDetail()
						})
					}
				})
			},
			shouhuo(id) {
				httpRequest.modal('提示', '是否确认收货', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/order/confirmOrder', 'POST', {
							id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							if(res.code==1){
								this.getDetail()
							}
						})
					}
				})
			},
			deleteorder(id) {
				httpRequest.modal('提示', '是否确认删除当前订单', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/order/delOrder', 'POST', {
							id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							setTimeout(() => {
								uni.navigateBack(1)
							}, 1000)
						})
					}
				})
			},
			tzljpj(id){
				uni.navigateTo({
					url:'/pages_wode/fabiaopj?id='+id
				})
			},
			// 跳转申请退款
			tzsqtk(pid,id){
				uni.navigateTo({
					url:'/pages_wode/shenqtuik?order_id='+pid+"&order_goods_id="+id
				})
			},
			tuikuanxq(id){
				uni.navigateTo({
					url:"/pages_wode/tuihuoxq?id="+id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.hexm {
		width: 167rpx;
		height: 167rpx;
		margin: auto;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.xhbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF9341;
		border-radius: 120rpx;
		border: 2rpx solid #FF9341;
	}

	.qxbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #666666;
		border-radius: 120rpx;
		border: 2rpx solid #666666;
	}

	.sptp {
		width: 124rpx;
		height: 124rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}
</style>